<{include file='../common/head.tpl'}>
<link href="/css/uploadify.css" rel="stylesheet">
<script src="/js/jquery.uploadify.min.js"></script>
<script type="text/javascript" src='/js/datepicker/WdatePicker.js'></script>
<div class="main w1060">
	<div class="twomain">
		<div class="biaoge">  
                    <h2 class="btzong2">添加报备 Network Records</h2>
                    <form name='myForm1' id='myForm1' method='post' action='/report/Doadd' autocomplete='off'>
			<table width="100%" border="0" cellspacing="0">
                            <tr>
                                <td>选择项目</td>
                                <td>
                                    <select name="project_id" autocomplete="off">
                                    <{foreach $project_list as $key => $val}>
                                    <option value="<{$val.project_id}>" <{if $info.project_id==$val.project_id}>selected="selected"<{/if}>><{$val.project_name}></option>
                                    <{/foreach}>
                                    </select>
                                </td>
                            </tr>
			  <tr>
				<td>开始时间：</td>
                                <td><input type="text" name="start_time" value="<{$info.start_time|date_format:"%Y-%m-%d"}>" id="d4311"  onClick="WdatePicker({minDate:'%y-%M-%d',maxDate:'#F{$dp.$D(\'d4312\')}'})" /></td>
			  </tr>
                          <tr>
				<td>结束时间：</td>
                                <td><input type="text" name="end_time" value="<{$info.end_time|date_format:"%Y-%m-%d"}>" id="d4312" onClick="WdatePicker({minDate:'#F{$dp.$D(\'d4311\')}'})" /></td>
			  </tr>
                          <tr>
				<td>报备内容：</td>
                                <td><textarea name="content" cols="60" rows="8" ><{$info.content}></textarea></td>
			  </tr>
                          <tr>
				<td>附件：</td>
                                <td>
                                    <input type='file' id="uploadify">(上传按CTRL键可以选择多个操作)
                                    <input type="hidden" id="nra_id" name="nra_id" value="" />
                                    <ul id="attach_list">
                                    <{if $attach}>
                                        <{foreach $attach as $key => $val}>
                                        <li id="attach_<{$val.nra_id}>"><a href="<{$val.url}>" target="_blank"><{$val.file_name}></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" onclick="del(<{$val.nra_id}>);">删除</a></li>
                                        <{/foreach}>
                                    <{/if}>
                                    </ul>
                                </td>
			  </tr>
                          <tr><td colspan="2"><input type="submit" id="submit" value="提交" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                  <input type="hidden" name="network_id" value="<{$network_id}>"/>
                                  <input type="hidden" name="nr_id" value="<{$nr_id}>" />
                              </td></tr>
		  </table>
                    </form>
		</div>
	</div>
</div>
<script>
    var nra_id = new Array();
        $(document).ready(function() {     
                var options = {         
                    beforeSubmit:  showRequest,  
                    success:       showResponse,
                    dataType:  'json'
                }
                $('#myForm1').ajaxForm(options); 
                
                
                $('#uploadify').uploadify({
                    'formData'      : {'network_id':<{$network_id}>},
                    'buttonText' : '选择文件',
                    'fileObjName' : 'upfile',   
                    'swf'      : '/js/uploadify.swf',
                    'fileTypeExts' : '*.*',
                    'uploader' : '/attachment/Baobei?attach_type=other',
                    'onUploadSuccess' : function(file, data, response) {
                        var obj = eval('(' + data + ')');
                        if (obj.state =='SUCCESS'){
                            alert('上传成功');
                            nra_id.push(obj.id);
                            $('#nra_id').val(nra_id.join(','));
                            $('#attach_list').append('<li id="attach_'+obj.id+'"><a href="'+obj.url+'" target="_blank">'+obj.file_name+'</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" onclick="del('+obj.id+');">删除</a></li>');
                        } else {
                            alert(obj.state);
                        }
                    } 
                });   
        });
            function showRequest(formData, jqForm, options) { 
                return true;
            }
            function showResponse(responseText, statusText, xhr, $form)  { 
                 
                if (responseText.status==1) {
                    $.layer({
                           shade: [0],
                           area: ['auto','auto'],
                           dialog: {
                               msg: '请选择操作？',
                               btns: 2,                    
                               type: 4,
                               btn: ['返回列表','继续添加'],
                               yes: function(){
                                    window.history.go(-1);
                               }, no: function(){
                                   window.location.reload();
                               }
                           }
                       });
                   
                } else {
                    alert(responseText.note); 
                }
            }
            //删除附件
            function del(nra_id){
                $.getJSON('/report/DelAttach',{nra_id:nra_id},function(res){
                    if (res.status == 1) {
                        $('#attach_'+nra_id).remove();
                    }
                    alert(res.note);
                });
            }
    </script>
<!--main End-->
<{include file="../common/footer.tpl"}>